package com.bangwz.aio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.CountDownLatch;

public class Client {

	public static void start() throws IOException, InterruptedException {
		AsyncClientHandler clientHandler = new AsyncClientHandler("127.0.0.1", 9527);
		new Thread(clientHandler, "Client").start();
		AsynchronousSocketChannel channel = clientHandler.getChannel();
		CountDownLatch latch = clientHandler.getLatch();

		Thread.sleep(500);
		ByteBuffer src = ByteBuffer.wrap("你好服务器。".getBytes());
		channel.write(src, src, new ClientWriteHandler(channel, latch));
	}

	public static void main(String[] args) {
		try {
			start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
